package com.rqf.ls.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.rqf.ls.service.IEvaluationService;
import com.server.date.DateUtil;

@Service("EvaluationService")
public class EvaluationService implements IEvaluationService {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	 /**
	 * 新增评价
	 * @param input
	 * @return
	 * @author ServerZhang
	 * @date 2016年3月29日
	 */
	@Override
	public Boolean add(Map<String, Object> input){
		String sql = "insert into pingjia (id,createtime,read,isable,pingjiawhoid,anwserid,content) values(PINGJIA_SEQUENCE.nextval,'%s',0,'1','%s','%s','%s')";
		String format = String.format(sql, DateUtil.getDateWithSeconds(new Date()),input.get("phoneNo"),input.get("anwserid"),input.get("content"));
		Boolean isSuccess = true;
		try {
			jdbcTemplate.execute(format);
		} catch (Exception e) {
			isSuccess = false;
		}
		return isSuccess;
	}
	
	@Override
	public Boolean addEvaluate(Map<String, Object> input){
		String sql = "insert into LAWYEREVA (id,createtime,EVA01,EVA02,EVA03,CONTENT01,CONTENT02,CONTENT03,QUESTIONID,ANSWERID,LAWYERPHONE,USERPHONE) "
				+ "values(LAWYEREVA_SEQUENCE.nextval,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')";
		String format = String.format(sql, DateUtil.getDateWithSeconds(new Date()),
				input.get("EVA01"),input.get("EVA02"),input.get("EVA03"),
				input.get("CONTENT01"),input.get("CONTENT02"),input.get("CONTENT03"),
				input.get("QUESTIONID"),input.get("ANSWERID"),input.get("LAWYERPHONE"),input.get("USERPHONE"));
		Boolean isSuccess = true;
		try {
			jdbcTemplate.execute(format);
		} catch (Exception e) {
			isSuccess = false;
		}
		return isSuccess;
	}
	
	@Override
	public Boolean update(Map<String, Object> input){
		Boolean isSuccess = true;
		return isSuccess;
	}
	@Override
	public Boolean delete(Integer id){
		String sql = "Delete from pingjia where id=%s";
		String format = String.format(sql,id);
		Boolean isSuccess = true;
		try {
			jdbcTemplate.execute(format);
		} catch (Exception e) {
			isSuccess = false;
		}
		return isSuccess;
	}
	 
	 /**
	 * 律师评价列表
	 * @param id
	 * @return
	 * @author ServerZhang
	 * @date 2016年3月29日
	 */
	@Override
	public List<Map<String, Object>> getList(String lawyerPhone) {
		String sql = "Select * from pingjia where pingjiawhoid='%s' order by createtime desc";
		String format = String.format(sql, lawyerPhone);
		List<Map<String, Object>> list = jdbcTemplate.queryForList(format);
		return list;
	}
}
